#include "videoshow.h"
#include <SDL.h>
#include <iostream>

VideoShow::VideoShow() {}

void VideoShow::videoShow()
{
    // 初始化函数,用于播放视频
    int res = SDL_Init(SDL_INIT_VIDEO);

    if(res != 0)
    {
        std::cout << "init failed" << std::endl;
    }

    // 创建SDL窗口
    auto window = SDL_CreateWindow("SDL窗口",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,
                                   800,600,SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);

    SDL_Renderer* renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED);

    // SDL_TEXTUREACCESS_TARGET 动态；SDL_TEXTUREACCESS_STATIC 静态
    SDL_Texture* texture = SDL_CreateTexture(
        renderer,SDL_PIXELFORMAT_RGBA8888,SDL_TEXTUREACCESS_TARGET,800,600);

    // 为渲染器设置纹理
    SDL_SetRenderTarget(renderer,texture);
    // 设置红色背景,后四个参数：RGBA
    SDL_SetRenderDrawColor(renderer,255,0,0,255);
    SDL_RenderClear(renderer);

    SDL_Rect rect;
    rect.x = 100;
    rect.y = 100;
    rect.w = 100;
    rect.h = 100;

    SDL_RenderDrawRect(renderer,&rect);
    SDL_SetRenderDrawColor(renderer,255,255,255,255);
    SDL_RenderFillRect(renderer,&rect);

    SDL_SetRenderTarget(renderer,NULL);
    SDL_RenderCopy(renderer,texture,NULL,NULL);
    SDL_RenderPresent(renderer);

    SDL_Delay(10000);

    // 销毁窗口
    SDL_DestroyWindow(window);

    // 释放
    SDL_Quit();
}
